package com.ruoyi.project.manhua.webLook.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.manhua.webLook.service.MhOverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 漫画章节 Controller
 *
 * @author yuan
 * @date 2021-01-13
 */
@Controller
@RequestMapping("/manhua/look/over")
public class MhoverController extends BaseController
{
    private String prefix = "manhua/look";


    @Autowired
    private MhOverService mhOverService;

    /**
     * 漫画详情页面请求
     * @return
     */
    @GetMapping("/{id}")
    public String over(@PathVariable("id")String id, ModelMap mmap)
    {
        boolean numeric = isNumeric(id);
        if(numeric){
            mmap.put("overData",mhOverService.overData(Long.valueOf(id)));
        }
        return prefix+"/over";
    }


    /**
     * 收藏
     * @return
     */
    @PostMapping("/collect")
    @ResponseBody
    public AjaxResult collect(@RequestParam("id")String id)
    {
        return AjaxResult.success(mhOverService.collectService(id));
    }

    /**
     * 正序 倒序
     * @return
     */
    @PostMapping("/order")
    @ResponseBody
    public AjaxResult order(@RequestParam("nameId")String nameId,@RequestParam("order")String order,@RequestParam("strip")Integer strip,@RequestParam("page")Integer page)
    {
        return AjaxResult.success(mhOverService.orderService(nameId,order,strip,page));
    }


    /**
     * 评论查询
     * @return
     */
    @PostMapping("/comment")
    @ResponseBody
    public AjaxResult comment(@RequestParam("nameId")String nameId,@RequestParam("strip")Integer strip, @RequestParam("page") Integer page)
    {
        return AjaxResult.success(mhOverService.commentServiceRedis(nameId,strip,page));
    }

    /**
     * 评论添加
     * @return
     */
    @PostMapping("/commentAdd")
    @ResponseBody
    public AjaxResult commentAdd(@RequestParam("nameId")String nameId,
                                 @RequestParam("text")String text,
                                 @RequestParam("id")Long id,
                                 @RequestParam("type")String type)
    {
        return AjaxResult.success(mhOverService.commentAddService(nameId,text,id,type));
    }


    /**
     * 点赞
     * @return
     */
    @PostMapping("/give")
    @ResponseBody
    public AjaxResult give(@RequestParam("id")Long id, @RequestParam("numder")Integer numder)
    {
        return AjaxResult.success(mhOverService.giveService(id,numder));
    }

    /**
     * 阅读
     * @param id 漫画id
     * @return
     */
    @PostMapping("/reading")
    @ResponseBody
    public AjaxResult reading(@RequestParam("id")Long id)
    {
        return AjaxResult.success(mhOverService.readingService(id));
    }


}
